#include<vector>
#include<iostream>
using namespace std;
class Solution {
public:
    vector<int> sortArray(vector<int>& nums) {
        srand(time(NULL));
        qsort(nums, 0, nums.size() - 1);
        return nums;
    }

    void qsort(vector<int>& nums, int l, int r) {
        if (l >= r)
            return;
        int key = getRandom(nums, l, r);
        int i = l, left = l - 1, right = r + 1;
        while (i < right) {
            if (nums[i] < key)
                swap(nums[i++], nums[++left]);
            else if (nums[i] == key)
                i++;
            else
                swap(nums[i], nums[--right]);
        }
        qsort(nums, l, left);
        qsort(nums, right, r);
    }
    int getRandom(vector<int>& nums, int left, int right) {
        int r = rand();
        return nums[r % (right - left + 1) + left];
    }
};

int main()
{
    Solution A;
    vector<int> nums{ 2,6,4,8,9,0,1,4,3,7 };
    A.sortArray(nums);
    for (auto e : nums)
    {
        cout << e << " " << endl;
    }
    return 0;
}